package com.ruoyi.swla2.service.impl;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.swla2.mapper.TaskManagementMapper;
import com.ruoyi.swla2.domain.TaskManagement;
import com.ruoyi.swla2.service.ITaskManagementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
/**
 * 任务管理Service业务层处理
 *
 * @author gdqt
 * @date 2025-06-26
 */
@Service
public class TaskManagementServiceImpl extends ServiceImpl<TaskManagementMapper, TaskManagement> implements ITaskManagementService
{
    @Autowired
    private TaskManagementMapper taskManagementMapper;

    /**
     * 查询任务管理
     *
     * @param id 任务管理主键
     * @return 任务管理
     */
    @Override
    public TaskManagement selectTaskManagementById(Long id)
    {

        return taskManagementMapper.selectById(id);
    }

    /**
     * 查询任务管理列表
     *
     * @param taskManagement 任务管理
     * @return 任务管理
     */
    @Override
    public List<TaskManagement> selectTaskManagementList(TaskManagement taskManagement)
    {
        LambdaQueryWrapper<TaskManagement> queryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(taskManagement.getTaskNo())){
            queryWrapper.eq(TaskManagement::getTaskNo,taskManagement.getTaskNo());
        }
        if(!StringUtils.isEmpty(taskManagement.getTaskName())){
            queryWrapper.eq(TaskManagement::getTaskName,taskManagement.getTaskName());
        }
        if(!StringUtils.isEmpty(taskManagement.getTaskAddress())){
            queryWrapper.eq(TaskManagement::getTaskAddress,taskManagement.getTaskAddress());
        }
        if(!StringUtils.isEmpty(taskManagement.getDesc())){
            queryWrapper.eq(TaskManagement::getDesc,taskManagement.getDesc());
        }
        if(!StringUtils.isEmpty(taskManagement.getStatus())){
            queryWrapper.eq(TaskManagement::getStatus,taskManagement.getStatus());
        }
        if(!StringUtils.isEmpty(taskManagement.getTaskStatus())){
            queryWrapper.eq(TaskManagement::getTaskStatus,taskManagement.getTaskStatus());
        }
        if(!StringUtils.isEmpty(taskManagement.getHeader())){
            queryWrapper.eq(TaskManagement::getHeader,taskManagement.getHeader());
        }
        if(!StringUtils.isEmpty(taskManagement.getTelephone())){
            queryWrapper.eq(TaskManagement::getTelephone,taskManagement.getTelephone());
        }
        if(taskManagement.getStartTime() != null){
            queryWrapper.le(TaskManagement::getStartTime,taskManagement.getStartTime());
            queryWrapper.ge(TaskManagement::getEndTime,taskManagement.getStartTime());
        }
        // if(taskManagement.getEndTime() != null){
        //     queryWrapper.eq(TaskManagement::getEndTime,taskManagement.getEndTime());
        // }
        return taskManagementMapper.selectList(queryWrapper);
    }


    @Override
    public List<TaskManagement> selectTaskManagementListByMap(Map<String, Object> params) {
        return taskManagementMapper.selectTaskManagementListByMap(params);
    }

    /**
     * 新增任务管理
     *
     * @param taskManagement 任务管理
     * @return 结果
     */
    @Override
    public int insertTaskManagement(TaskManagement taskManagement)
    {
        return taskManagementMapper.insert(taskManagement);
    }

    /**
     * 修改任务管理
     *
     * @param taskManagement 任务管理
     * @return 结果
     */
    @Override
    public int updateTaskManagement(TaskManagement taskManagement)
    {
        taskManagement.setUpdateTime(DateUtils.getNowDate());
        return taskManagementMapper.updateById(taskManagement);
    }

    /**
     * 批量删除任务管理
     *
     * @param ids 需要删除的任务管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTaskManagementByIds(Long[] ids)
    {
        return taskManagementMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除任务管理信息
     *
     * @param id 任务管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTaskManagementById(Long id)
    {
        return taskManagementMapper.deleteById(id);
    }


    @Override
    public int updateByIdNew(TaskManagement taskManagement) {
        return taskManagementMapper.updateByIdNew(taskManagement);
    }
}
